home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / NGL2.0.1J(68k).sit / NGL2.0.1J(68k) / Hit Sample / Hit Sample.c < prev    next >
C/C++ Source or Header  |  1996-09-30  |  3KB  |  150 lines

  1. /*============================================================
  2.  
  3.                     Hit サンプルプログラム
  4.                     
  5. ============================================================*/
  6. #include        "N_Library.h"
  7.  
  8. void Main_Loop(void);
  9.  
  10. short        Data_Rsrc = 0;
  11. long            total_step = 0;
  12. long            wait;
  13. short        i,xx,yy,r=0;
  14. short        x[128];
  15. short        y[128];
  16. float            ht[128];
  17. float            m[128];
  18. float            sp[128];
  19. short        vc[128];
  20. short        pat[128];
  21. Boolean        Snd_Flg = false;
  22. Point            mp;
  23. short        col = 0;
  24. short        col_pat[] = {0,0,1,1,2,2,3,3,3,3,2,2,1,1,0,0};
  25. short        sound_list[] = { 9000,0 };
  26. short        rt[128];
  27.  
  28. void main(void)
  29. {
  30.     WindowPtr    window;
  31.     Rect            BGrect;
  32.     short        p;
  33.  
  34.     ToolboxInit();
  35.     ColorCheck();
  36.     HideMenuBar();
  37.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  38.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  39.      Open_Resource_File(128,1,&Data_Rsrc);
  40.  
  41.     N_Sound_Load(&sound_list[0]);
  42.     N_Sp_Make(640,480);                                                //スプライト・セルの表示有効範囲
  43.     N_Cel_Make(350000);                                                //画面に表示させるセルパターンの総ドット数は最低必要
  44.     HideCursor();
  45.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  46.     N_Sprite_Set(129,0,48,48,0,1,1,4);                                    //Sp 0 にパターンを登録(回転付きモード)
  47.     N_Sprite_Set(201,80,32,32,0,1,1,0);                                    //Sp 80 にパターンを登録(背景用)
  48.     N_Sprite_Set(202,81,32,32,0,1,1,0);                                    //Sp 81 にパターンを登録(背景用)
  49.     N_Sprite_Set(130,82,32,32,0,1,1,0);                                    //Sp 82
  50.     N_Sprite_Set(131,83,32,32,0,1,1,0);                                    //Sp 83
  51.     N_Sprite_Set(132,84,32,32,0,1,1,0);                                    //Sp 84
  52.     N_Sprite_Set(133,85,32,32,0,1,1,0);                                    //Sp 85
  53.     N_Sprite_Set(134,86,32,32,0,1,1,0);                                    //Sp 86
  54.     Delay(60,&wait);
  55.     Close_Resource_File(&Data_Rsrc);
  56.  
  57.     for (i=0;i!=128;i++)                                                    //128個分の初期位置・速度を配列に入れる
  58.     {
  59.         x[i] = GetRandom(0,640-48);
  60.         y[i] = 0;
  61.         ht[i] = GetRandom(0,19);
  62.         m[i] = GetRandom(7,21);
  63.         sp[i] = 0.5;
  64.         pat[i] = 0;
  65.         if (GetRandom(0,1) == 0) vc[i] = 4; else vc[i] = -4;
  66.     }
  67.  
  68.     for (yy=0;yy!=15;yy++)
  69.     {
  70.         for (xx=0;xx!=20;xx++)
  71.         {
  72.             if (GetRandom(0,1)==0)
  73.                 N_Sp_Put(0x80000000+80,xx*32,yy*32);
  74.                 else N_Sp_Put(0x80000000+81,xx*32,yy*32);
  75.         }
  76.     }
  77.  
  78.     Begin_Timer_Int(Main_Loop,55);
  79.     do
  80.     {
  81.     }
  82.     while (!Button());
  83.     Stop_Timer_Int();
  84.  
  85.     N_Sound_Close();
  86.     FlushEvents( everyEvent, 0 ); 
  87.     ColorRevert();
  88.     ShowMenuBar();
  89.     ShowCursor();
  90. }
  91.  
  92.  
  93. void Main_Loop(void)
  94. {
  95.     Boolean    flg = false;
  96.     Boolean    hit = false;
  97.  
  98.     for (i=0;i!=8;i++)    
  99.     {
  100.         if (m[i]<ht[i])
  101.         {
  102.             sp[i] = -0.8;
  103.         }
  104.         else
  105.         if (-m[i]>ht[i])
  106.         {
  107.             sp[i] = 0.8;
  108.         }
  109.  
  110.         ht[i] = ht[i] + sp[i];
  111.         y[i] = ht[i]*ht[i] + 426 - m[i]*m[i];
  112.         x[i] = x[i] + vc[i];
  113.         
  114.         if (vc[i]>0)
  115.         {
  116.             if (x[i]>=592) vc[i] = -4;
  117.  
  118.             pat[i] = pat[i] + 2;
  119.             if (pat[i] >= 64) pat[i] = 0;
  120.         }
  121.         if (vc[i]<0)
  122.         {
  123.             if (x[i]<=0) vc[i] = 4;
  124.             pat[i] = pat[i] - 2;
  125.             if (pat[i] <= -1) pat[i] = 63;
  126.         }
  127.         N_Cel_Put(i,0x80000000+pat[i],x[i],y[i]);
  128.  
  129.         flg = N_Cel_Hit2(i,101);
  130.         if (flg == true) hit = true;
  131.     }
  132.     if (hit == false)
  133.     {
  134.         Snd_Flg = false;
  135.     }
  136.  
  137.     if ((hit == true) && (Snd_Flg == false))
  138.     {
  139.         N_Sound_Play(9000);
  140.         Snd_Flg = true;
  141.     }
  142.     col++;
  143.     col = col & 0x0f;
  144.     GetMouse(&mp);
  145.     N_Cel_Put(100,0x80000000+82,mp.h,mp.v);
  146.     N_Cel_Put(101,0x80000000+83+col_pat[col],mp.h,mp.v);
  147.     N_Cel_Loop(0,0);
  148. }
  149.  
  150.